Function to ingest data from NOAA ERDDAP (https://polarwatch.noaa.gov/erddap). This code is specific to a chosen area covering the Antarctic Peninsula.
ingest.ice.data <- function(date){
x <- read.csv(url(paste0("https://polarwatch.noaa.gov/erddap/griddap/nsidcG02202v4sh1day.csv?cdr_seaice_conc%5B(",date,"T00:00:00Z):1:(",date,"T00:00:00Z)%5D%5B(3212500.0):1:(162500.0)%5D%5B(-2887500.0):1:(62500.0)%5D")))[-1,]
x <- x[x$cdr_seaice_conc != 2.53,] #remove artifact
x <- x[complete.cases(x),] # remove empty rows
print(mean(x[,4])) #prints mean ice concentration for that day in the defined region
}
Create a dataframe with dates of interest.
df <- data.frame()
d <- 2
j <- 0
i <- 1
r <- 2
df[1,1] <- "2022-12-01"
repeat{
df[r,1] <- paste0("2022-12-",as.character(j),as.character(d))
d = d + 1
r = r + 1
if (d > 9){
j = j + 1
d <- 0
}
if (j == 3){
df[r,1] <- "2022-12-30"
rm(d,i,j,r)
break
}
}
Download and process daily data and calculate mean percent ice concentration for each day of interest.
for (i in 1:nrow(df)){
df[i,2] <- round(ingest.ice.data(df[i,1]),3)*100
}
## [1] 0.4690225
## [1] 0.4691108
## [1] 0.4695511
## [1] 0.4627146
## [1] 0.4588892
## [1] 0.4585602
## [1] 0.4538993
## [1] 0.4443127
## [1] 0.4371012
## [1] 0.426517
## [1] 0.4043453
## [1] 0.3877448
## [1] 0.3775204
## [1] 0.3706369
## [1] 0.3603472
## [1] 0.35466
## [1] 0.3446983
## [1] 0.3283127
## [1] 0.3144902
## [1] 0.2989305
## [1] 0.2914475
## [1] 0.279953
## [1] 0.2694264
## [1] 0.2582974
## [1] 0.2506561
## [1] 0.24607
## [1] 0.2436307
## [1] 0.2376412
## [1] 0.2283175
## [1] 0.2220106
colnames(df) <- c("date","average_percent")
df[,1]<-lubridate::ymd(df$date)
View the data
## date average_percent
## 1 2022-12-01 46.9
## 2 2022-12-02 46.9
## 3 2022-12-03 47.0
## 4 2022-12-04 46.3
## 5 2022-12-05 45.9
## 6 2022-12-06 45.9
## 7 2022-12-07 45.4
## 8 2022-12-08 44.4
## 9 2022-12-09 43.7
## 10 2022-12-10 42.7
## 11 2022-12-11 40.4
## 12 2022-12-12 38.8
## 13 2022-12-13 37.8
## 14 2022-12-14 37.1
## 15 2022-12-15 36.0
## 16 2022-12-16 35.5
## 17 2022-12-17 34.5
## 18 2022-12-18 32.8
## 19 2022-12-19 31.4
## 20 2022-12-20 29.9
## 21 2022-12-21 29.1
## 22 2022-12-22 28.0
## 23 2022-12-23 26.9
## 24 2022-12-24 25.8
## 25 2022-12-25 25.1
## 26 2022-12-26 24.6
## 27 2022-12-27 24.4
## 28 2022-12-28 23.8
## 29 2022-12-29 22.8
## 30 2022-12-30 22.2
To plot daily data:
p <- plot_ly(data = df, x = ~date, y = ~average_percent, mode = "lines", type = "scatter",
#we name the first line (sunrise) and edit the info for the mousover and change
#the color and "thickness" of the line
name = "%", line=list(width=5, color = "#ffca7c"))